<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约列表
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findMatchPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <el-button type="primary" class="butT" @click="handleDeleteMany()">批量删除</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row
                      ref="multipleTable">
                <el-table-column align="center" type="selection"></el-table-column>
                <el-table-column prop="orderDates" align="center" label="预约日期"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column sortable prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" width="200" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确定预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!--新增标签弹层-->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px" :model="formData" :rules="rules"
                                         ref="formData">
                                    <el-row>
                                        <el-col :span="10">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="10">
                                            <el-form-item label="预约日期">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        :picker-options="pickerOptions"
                                                        @blur="handleOrdersetting()">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="10">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="14">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="11">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="10">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        :picker-options="pickerOptions1">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="s in tableData">
                                            <td>
                                                <input :id="s.id" v-model="setmealId" type="radio" :value="s.id">
                                            </td>
                                            <td><label :for="s.id">{{s.code}}</label></td>
                                            <td><label :for="s.id">{{s.name}}</label></td>
                                            <td><label :for="s.id">{{s.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>


        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            multipleSelection: [],
            activeName: 'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            setmealId: '',
            rules: {
                phoneNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'},
                    {pattern: /^[1][3,4,5,7,8][0-9]{9}$/, message: '请输入正确的手机号'}
                ],
                idCard: [{required: true, message: '身份证号为必填项', trigger: 'blur'},
                    {pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '请输入正确的身份证号'}
                ]
            },
            pickerOptions: {
                disabledDate(time) {
                    let curDate = (new Date()).getTime();
                    let three = 30 * 24 * 3600 * 1000;
                    let threeMonths = curDate + three;
                    return time.getTime() < Date.now() || time.getTime() > threeMonths;
                },
            },
            pickerOptions1: {
                disabledDate(time) {
                    return time.getTime() > Date.now();
                },
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//VUE对象初始化完成后调用分页查询方法, 完成分页查询
        },
        methods: {
            findMatchPage() {
                this.pagination.currentPage = 1,
                    this.findPage();
            },
            //分页查询
            findPage() {
                //发送ajax请求, 提交分页相关请求参数(页码 每页记录数 查询条件)
                var param = {
                    currentPage: this.pagination.currentPage, //页码
                    pageSize: this.pagination.pageSize, //每页显示的记录数
                    queryString: this.pagination.queryString //查询条件
                };
                //请求后台
                axios.post("/ordersetting/findPage.do", param).then((res) => {
                    //解析Controller响应的数据为模型数据赋值
                    //为模型数据赋值, 基于voe的双向绑定显示到页面
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新的页码
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },
            //批量删除
            handleDeleteMany() {
                this.multipleSelection = [];
                this.multipleSelection = this.$refs.multipleTable.selection;
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post("/ordersetting/deletemany.do", this.multipleSelection).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '删除失败!'
                            });
                        }
                        //调用分页, 获取最新分页数据
                        this.findPage();
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/ordersetting/delete.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '删除失败!'
                            });
                        }
                        //调用分页, 获取最新分页数据
                        this.findPage();
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //权限不足提示
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            resetForm() {
                this.formData = {};
            },
            handleOrdersetting() {
                axios.post("/ordersetting/queryOrdersetting.do", this.formData).then((res) => {
                    if (!res.data.flag) {
                        this.$message.error("当前预约日期已满或者未设置预约人数")
                    }
                })
            },
            handleAdd() {
                //发送ajax请求, 将表单数据提交到后台进行处理
                axios.post("/ordersetting/add.do?setmealIds=" + this.setmealId, this.formData).then((res) => {
                    //关闭新增窗口
                    this.dialogFormVisible = false;
                    if (res.data.flag) {
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        this.$message.error(res.data.message)
                    }
                    //重新分页查询
                    this.findPage();
                });
            },
            handleUpdate(row) {
                axios.get("/ordersetting/confirmOrder.do?id=" + row.id + "&telephone=" + row.phoneNumber).then((res) => {
                    if (res.data.flag) {
                        this.$message.success(res.data.message);
                        this.findPage();
                    } else {
                        this.$message.error("确认预约失败！")
                    }
                })
            },
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm();
                //默认切换到第一个标签页
                this.activeName = 'first';
                //重置第二个标签页复选框
                this.setmealId = '';
                axios.get("/setmeal/findAllSetmeal.do").then((res) => {
                    if (res.data.flag) {
                        //弹出提示信息
                        this.tableData = res.data.data;
                    } else {
                        //执行失败 弹出提示
                        this.$message.error(res.data.message);
                    }
                });
            },
        }
    })
</script>


</html>